using System;

using System.Linq;
using System.Text;
using System.Transactions;
using System.Collections.Generic;
 using EF.Commons.Background.Entity;

namespace Common.Background.Data
{

    /// <summary>
    /// 
    /// </summary>
    public class WebManageRolesRepository : BackgroundRepositoryBase, IWebManageRolesRepository
    {
        #region IWebManageRolesRepository 成员

        /// <summary>
        /// 职位设置
        /// </summary>
        /// <param name="WebManageRoles"></param>
        public void SetWebManageRoles(WebManageRoles webManageRoles)
        {
            using (TransactionScope tran = new TransactionScope())
            {
                try
                {
                    var iWebManageRolesRepository = new WebManageRolesRepository();
                    var iWebManageRole_WebManageMenusRepository = new WebManageRole_WebManageMenusRepository();
                    var list = new List<WebManageRole_WebManageMenus>();
                    iWebManageRole_WebManageMenusRepository.DeleteByRoleID(webManageRoles.ManageRoleID);

                    foreach (var i in webManageRoles.WebManageRole_WebManageMenus_Extend)
                    {
                        list.Add(new WebManageRole_WebManageMenus { ManageRoleID = webManageRoles.ManageRoleID, MenuID = i.MenuID });
                    }
                    iWebManageRole_WebManageMenusRepository.Insert(list);
                    webManageRoles.UpdateDate = DateTime.Now.ToString("yy-MM-dd");
                    base.Update<WebManageRoles>(webManageRoles);
                    tran.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    tran.Dispose();
                }
            }
        }


        #endregion

        #region IWebDepartmentsRepository 成员

        public IQueryable<WebManageRoles> GetModel()
        {
            return GetEntities<WebManageRoles>();
        }

        public WebManageRoles Find(params object[] valueKeys)
        {
            return GetEntity<WebManageRoles>(valueKeys);
        }

        #endregion
    }
}
